<?php

/**
 * Controleur permettant de lister l'ensemble des clients
 */
require_once('dao/ClientDao.php');
if ($_SESSION['niveauAuth']<>'0' ){
// Initialisation des variables
$searchId = "";

// Id du client à afficher
if(isset($_GET['id'])){
	$clients = ClientDao::searchById($_GET['id']);
		if (count($clients) == 0){
		$error="Aucun client trouvé";
		
	}
}
//mise a jour client
if (isset($_POST['action'])){
	if ($_POST['action'] == "update"){
$code_client_hto = $_POST['code_client_hto'];		
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$cp = $_POST['cp'];
$adresse = $_POST['rue'];
$ville = $_POST['ville'];
$pays = $_POST['pays'];
$raison_social = $_POST['rs'];
$forme_juridique = $_POST['fj'];
$siret = $_POST['siret'];
$rcs = $_POST['rcs'];
$ape = $_POST['ape'];
$activite = $_POST['activite'];
$tel_fix = $_POST['fixe'];
$tel_fax = $_POST['fax'];
$tel_mobile = $_POST['mobile'];
$email = $_POST['couriel'];
$site_internet = $_POST['site_internet'];
$rib = $_POST['rib'];
$code_iban = $_POST['code_iban'];
$code_etablissement = $_POST['code_etablissement'];
$swift = $_POST['swift'];
$code_guichet = $_POST['code_guichet'];
$num_compte = $_POST['num_compte'];
$banque = $_POST['banque'];
$adresse_bq = $_POST['adresse_bq'];
$cp_banque = $_POST['cp_banque'];
$ville_bq = $_POST['ville_bq'];
$mode_paiement = $_POST['mode_paiement'];
$civilite = $_POST['civilite'];
$raison_social_dif = $_POST['raison_social_dif'];
$adresse_dif = $_POST['adresse_dif'];
$cp_dif = $_POST['cp_dif'];
$ville_dif = $_POST['ville_dif'];
$telephone_dif = $_POST['telephone_dif'];
$email_gest = $_POST['email_gest'];
$site_internet = $_POST['site_internet'];
if($_POST['facture_detail']){$facture_detail = 'x';}else{$facture_detail = '';}
$vendeur = $_POST['vendeur'];	
}
else {
	$abonnement_voip = null;
	$minute_voip = null;
	$grille_tarifaire_voip =null;
	$abonnement_vga = null;
	$minute_vga = null;
	$grille_tarifaire_vga = null;

}	




$updateOK = ClientDao::update($code_client_hto,$nom,$prenom,$cp,$adresse,$ville,$pays,$raison_social,$forme_juridique,$rcs,$ape,$activite,$tel_fix,$tel_fax,$tel_mobile,$email,$site_internet,$siret,$rib,$code_iban,$code_etablissement,$swift,$code_guichet,$num_compte,$banque,$adresse_bq,$cp_banque,$ville_bq,$mode_paiement,$civilite,$raison_social_dif,$adresse_dif,$cp_dif,$ville_dif,$telephone_dif,$email_gest,$site_internet,$facture_detail,$vendeur);
		
		if ($updateOK){
			$message="Mise à du client réalisée";
			header('location: liste-client');
			
			
		} else {
			$error = "Mise à jour impossible";
		}

	}



// Rendu de la page
echo $twig->render('detail-client.html', 
		array(	'client' => $clients[0],
				'searchId' => $searchId, 
				'message' => $message, 
				'error' => $error));

}
else {
	redirect("home-admin");
}
